package org.lql.algo.codecrush.hot100.greedy;

/**
 * @author: liangqinglong
 * @date: 2025-09-16 09:12
 * @description: 121. 买卖股票的最佳时机 <a href="https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class MaxProfit {

	public int maxProfit(int[] prices) {
		int min = Integer.MAX_VALUE;
		int max = 0;
		for (int price : prices) {
			if (price < min) {
				min = price;
			}
			if (price - min > max) {
				max = price - min;
			}
		}
		return max;
	}

	public static void main(String[] args) {
		int[] prices = {7, 1, 5, 3, 6, 4};
		MaxProfit maxProfit = new MaxProfit();
		System.out.println(maxProfit.maxProfit(prices));
	}
}
